/**
 * Created by luomingzhong on 16/12/25.
 */
import React, {Component} from 'react';
import {goAction, cautionAction, stopAction} from './actions';

class Buttons extends Component {

    componentWillMount() {
        this.props.store.subscribe(() => {
            this.forceUpdate();
        })
    }

    render() {
        const state = this.props.store.getState();
        return (
            <div style={{textAlign: 'center'}}>
                <button
                    onClick={() => {
                        this.props.store.dispatch(goAction)
                    }}
                    disabled={state == 'GO' || state == 'CAUTION'}
                >
                    Go
                </button>
                <button
                    onClick={() => {
                        this.props.store.dispatch(cautionAction)
                    }}
                    disabled={ state == 'CAUTION' || state == "STOP"}
                >
                    Caution
                </button>
                <button onClick={() => {
                    this.props.store.dispatch(stopAction)
                }}
                        disabled={state == "STOP" || state == "GO"}
                >
                    Stop
                </button>
            </div>
        )
    }
}
export default Buttons;